<template>

	<keep-alive>
		<router-view class="router-view" v-slot="{ Component }">
			<transition :name="transitionName" appear="true">
				<component :is="Component"/>
			</transition>
		</router-view>	
	</keep-alive>
		
	
</template>

<script>
import { reactive,toRefs } from "@vue/reactivity";
import { useRouter } from "vue-router";

export default {
  name: 'App',
   setup(){
	   const router = useRouter();
       // 创建响应式数据
	   const state = reactive({
	 	 transitionName: "slide-left", 
	   });
	  
	   router.beforeEach((to, from)=>{
	 	  if ( to.meta.index > from.meta.index ){
	 		  state.transitionName = "slide-left";
	 	  } else if (to.meta.index < from.meta.index ){
	 		  state.transitionName = "slide-right";
	 	  } else {
	 		  state.transitionName = "";
	 	  }
	   });
	  
	   return {
	 	  ...toRefs(state),
	   };
	 },
	// components:{
		
	// },
};
</script>

<style>
body,
html {
  margin: 0;
  padding: 0;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

.router-view {
  width: 100%;
  height: auto;
  position: absolute;
  top: 0;
  bottom: 0;
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
}

.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  height: 100%;
  will-change: transform;
  transition: all 500ms;
  position: absolute;
  backface-visibility: hidden;
}
.slide-right-enter {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}
.slide-right-leave-active {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
.slide-left-enter {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
.slide-left-leave-active {
  opacity: 0;
  z-index: 1;
  transform: translate3d(-100%, 0, 0);
}
</style>
